package cn.tedu.hospital.admin.server.user.service.impl;

import cn.tedu.hospital.admin.server.user.dao.persist.repository.IUserRegRepository;
import cn.tedu.hospital.admin.server.user.pojo.entity.UserReg;
import cn.tedu.hospital.admin.server.user.pojo.param.UserAddNewParam;
import cn.tedu.hospital.admin.server.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 处理用户数据的业务实现类
 *
 * @author qiqiang@deng
 * @version 1.0
 */
@Slf4j
@Service
public class UserRegServiceImpl implements IUserService {

    @Autowired
    private IUserRegRepository userRepository;

    public UserRegServiceImpl(){
        log.debug("创建业务类对象：UserServiceImpl");
    }

    @Override
    public void addNew(UserAddNewParam userAddNewParam) {
        log.debug("开始处理【添加用户】的业务，参数：{}", userAddNewParam);

        UserReg userReg = new UserReg();
        //复制属性
        BeanUtils.copyProperties(userAddNewParam, userReg);
        String rawPassword = userReg.getPassword();
        userReg.setPassword(rawPassword);
        int rows = userRepository.insert(userReg);
        if (rows != 1){
            String message = "添加用户失败，服务器忙。请稍后再尝试！";
            log.warn(message);

        }
    }
}
